﻿using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Security;
using System.Text;

namespace System.Peppers.Win32
{
    [SuppressUnmanagedCodeSecurity]
    internal class Mpr
    {
        protected const string DLL = "mpr.dll";

        [DllImport(DLL)]
        public static extern int WNetAddConnection2([In] NETRESOURCE netResource, string password, string username, WNetFlags flags);

        [DllImport(DLL)]
        public static extern int WNetCancelConnection2(string lpName, WNetFlags dwFlags, bool bForce);

        [DllImport(DLL, CharSet = CharSet.Auto)]
        public static extern int WNetGetConnection([In] string lpLocalName, [Out, MarshalAs(UnmanagedType.LPTStr)] StringBuilder lpRemoteName, [In, Out] ref int lpnLength);

        [DllImport(DLL, CharSet = CharSet.Auto)]
        public static extern int WNetGetUser([In] string lpName, [Out, MarshalAs(UnmanagedType.LPTStr)] StringBuilder lpUserName, [In, Out] ref int lpnLength);

        [DllImport(DLL)]
        public static extern int WNetOpenEnum([In] RESOURCESCOPE dwScope, [In] RESOURCETYPE dwType, [In] RESOURCEUSAGE dwUsage, [In] NETRESOURCE lpNetResource, [Out] out IntPtr lphEnum);

        [DllImport(DLL)]
        public static extern int WNetCloseEnum([In] IntPtr hEnum);

        [DllImport(DLL, CharSet = CharSet.Auto)]
        public static extern int WNetEnumResource([In] IntPtr hEnum, [In, Out] ref int lpcCount, [Out] IntPtr lpBuffer, [In, Out] ref int lpBufferSize);

        protected Mpr() { }
    }
}
